package com.zhupanlin.springsecurity.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/12/12 23:19
 */
@RestController
public class HelloController {

    @Autowired
    private AuthenticationManager authenticationManager;

    @RequestMapping("/hello")
    public String hello() {
        System.out.println("hello security");
        // 1.获取认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println("身份信息 = " + authentication.getPrincipal());
        System.out.println("权限信息 = " + authentication.getAuthorities());
        new Thread(() -> {
            Authentication authentication1 = SecurityContextHolder.getContext().getAuthentication();
            System.out.println("authentication1 = " + authentication1);
        }).start();
        return "hello security";
    }

}
